package com.jianan.mis.app;

import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.swt.graphics.Point;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.jianan.mis.sys.IAppConstants;
import com.jianan.mis.sys.IImageKeys;
import com.jianan.mis.sys.ImageManager;
import com.jianan.mis.sys.ResourceManager;
import com.jianan.mis.sys.SystemTray;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

	private SystemTray systemTray;

	public ApplicationWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		super(configurer);
	}

	public ActionBarAdvisor createActionBarAdvisor(
			IActionBarConfigurer configurer) {
		return new ApplicationActionBarAdvisor(configurer);
	}

	public void preWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		configurer.setInitialSize(new Point(400, 300));
		configurer.setShowCoolBar(true);
		configurer.setShowStatusLine(true);
		configurer.setShowPerspectiveBar(true);
		configurer.setTitle(IAppConstants.APPLICATION_TITLE);
	}

	public void postWindowOpen() {
		// 窗体最大化
		this.getWindowConfigurer().getWindow().getShell().setMaximized(true);
		// 创建系统托盘
		createSystemTray();
		// 设置状态栏信息
		IStatusLineManager statusLine = getWindowConfigurer()
				.getActionBarConfigurer().getStatusLineManager();
		statusLine.setMessage(ImageManager.getImage(IImageKeys.AUTHOR),
				"Powered by HuangJun");
	}

	/**
	 * 创建系统托盘
	 * 
	 */
	private void createSystemTray() {
		systemTray = new SystemTray();
		systemTray.createSysTray(getWindowConfigurer().getWindow());
	}

	/*
	 * public boolean preWindowShellClose() {
	 * systemTray.windowMinimized(getWindowConfigurer().getWindow().getShell());
	 * return false; }
	 */

	public void dispose() {
		systemTray.dispose();
		ResourceManager.dispose();
	}
}
